package com.example.triangle;

import androidx.appcompat.app.AppCompatActivity;

import android.opengl.GLSurfaceView;
import android.os.Bundle;

import com.example.triangle.databinding.ActivityMainBinding;

public class MainActivity extends AppCompatActivity {
    private MyGLRenderer javaRenderer=null ;

    private ActivityMainBinding binding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        binding = ActivityMainBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());


        binding.javabutton.setOnClickListener(view -> {
            javaRenderer=new MyGLRenderer(this,false);
            GLSurfaceView glsurface=new GLSurfaceView(MainActivity.this);
            setContentView(glsurface);
            glsurface.setEGLContextClientVersion(2);//必须设置，用来确定opengl版本
            glsurface.setRenderer(javaRenderer);
            binding.javabutton.setClickable(false);
            binding.cppbutton.setClickable(false);
        });
        binding.cppbutton.setOnClickListener(view -> {
            javaRenderer=new MyGLRenderer(this,true);
            GLSurfaceView glsurface=new GLSurfaceView(MainActivity.this);
            setContentView(glsurface);
            glsurface.setEGLContextClientVersion(2);//必须设置，用来确定opengl版本
            glsurface.setRenderer(javaRenderer);
            binding.javabutton.setClickable(false);
            binding.cppbutton.setClickable(false);
        });
    }
}